Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding an interface to the system socket to help nydusd obtain config #504

Merged
merged 8 commits into from
Oct 31, 2023

Conversation

DarkMountain-wyz
Copy link

Issue

https://github.com/containerd/nydus-snapshotter/issues/388

Details

  • Add interface endpointGetDaemonConfig string="/api/v1/daemons/{id}/config" in system. go
  • Add handler func getDaemonConfig() to deliver config
  • Pass the system socket and URL to nydusd through command-line arguments

@codecov
Copy link

codecov bot commented Jul 9, 2023

Codecov Report

Merging #504 (402b9e4) into main (dde2109) will increase coverage by 0.05%.
Report is 6 commits behind head on main.
The diff coverage is 38.55%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #504      +/-   ##
==========================================
+ Coverage   33.56%   33.61%   +0.05%     
==========================================
  Files          65       65              
  Lines        8176     8259      +83     
==========================================
+ Hits         2744     2776      +32     
- Misses       5117     5167      +50     
- Partials      315      316       +1     
Files Coverage Δ
config/config.go 32.37% <ø> (ø)
config/global.go 22.93% <0.00%> (-0.43%) ⬇️
pkg/daemon/command/command.go 54.86% <0.00%> (-2.02%) ⬇️
config/daemonconfig/daemonconfig.go 35.55% <86.48%> (+35.55%) ⬆️
pkg/manager/daemon_adaptor.go 0.00% <0.00%> (ø)
pkg/system/system.go 4.79% <0.00%> (-0.69%) ⬇️

@sctb512
Copy link
Member

sctb512 commented Jul 12, 2023

#388

The link for this issue is not valid.

pkg/daemon/command/command.go Outdated Show resolved Hide resolved
pkg/manager/daemon_adaptor.go Outdated Show resolved Hide resolved
@sctb512
Copy link
Member

sctb512 commented Jul 12, 2023

  • Pass the system socket and URL to nydusd through command-line arguments

I am confused why we need this API? Could you tell me more about this?

@sctb512
Copy link
Member

sctb512 commented Jul 12, 2023

Related to dragonflyoss/nydus#1361

@DarkMountain-wyz
Copy link
Author

  • Pass the system socket and URL to nydusd through command-line arguments

I am confused why we need this API? Could you tell me more about this?

My initial plan was to provide an API in nydusd to pass config from SN to nydusd, but this would require opening the socket before creating the daemon. The thread creating the daemon would need to block until the API server thread received the passed config. Similarly, in SN, it is necessary to block after sending the config until the daemon is created. In the original logic, once the SN establishes a connection with the socket, it is considered that the daemon has been created. I think such changes will have a significant impact, bringing many uncontrollable impacts. Therefore, the current solution is to request config from nydusd to SN. This will not change the original Logical framework, but also add control items that are compatible with the old version of nydusd.

@changweige
Copy link
Member

Is it possible only add the capability to nydus-snapshotter to share registry credentials to nydusd when nydusd requires it?
Other part of items should be persisted on disk like what we do now.

@imeoer
Copy link
Collaborator

imeoer commented Jul 31, 2023

I think in addition to considering that credentials cannot be persisted, we also need to consider how to promptly renew the registry token using the new registry user/pass when it changed (for example when a credential helper is used).

And how nydusd can use the updated config when serving new images after the user updates the nydusd config (for example tune the prefetch setting).

Therefore, I think it is feasible to have the snapshotter provide this API.

@changweige
Copy link
Member

Sorry, need rebase

Copy link
Member

@changweige changweige left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, but we may need more work to do

config/config.go Outdated Show resolved Hide resolved
config/daemonconfig/daemonconfig.go Outdated Show resolved Hide resolved
pkg/daemon/command/command.go Outdated Show resolved Hide resolved
pkg/manager/daemon_adaptor.go Outdated Show resolved Hide resolved
pkg/system/system.go Outdated Show resolved Hide resolved
pkg/system/system.go Outdated Show resolved Hide resolved
@DarkMountain-wyz
Copy link
Author

DarkMountain-wyz commented Aug 6, 2023

The method has changed, and now snapshotter supports providing backend config to nydus instead of writing files.

config/config.go Outdated Show resolved Hide resolved
misc/snapshotter/config.toml Outdated Show resolved Hide resolved
config/daemonconfig/fuse.go Outdated Show resolved Hide resolved
@DarkMountain-wyz
Copy link
Author

Hello @sctb512 @changweige , I've submitted a Pull Request that introduces a new implementation approach. In this approach, the backend configuration's Auth information is not persisted. Instead, during the startup of nydusd, a URL is provided, and nydusd retrieves the Auth information by making a request to this URL. This design aims to enhance the security. Please review and share your thoughts on this approach. Thank you!

@imeoer
Copy link
Collaborator

imeoer commented Aug 22, 2023

@DarkMountain-wyz It seems we need to fix the CI.

@DarkMountain-wyz
Copy link
Author

@DarkMountain-wyz It seems we need to fix the CI.

I will fix it.

@changweige
Copy link
Member

need rebase

@DarkMountain-wyz
Copy link
Author

need rebase

@changweige it has been rebased now.

c.Device.Backend.Config.Auth = backendAuth
c.Device.Backend.Config.RegistryToken = registryToken
return err
case BackendTypeOss:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The s3 backend should also be handled. :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a more elegant way would be to use struct tags and reflect, for example:

type BackendConfig struct {
	...
	Auth               string         `json:"auth,omitempty" secret:"true"`
	RegistryToken      string         `json:"registry_token,omitempty" secret:"true"`

	AccessKeyID     string `json:"access_key_id,omitempty" secret:"true"`
	AccessKeySecret string `json:"access_key_secret,omitempty" secret:"true"`
  ...
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The s3 backend should also be handled. :)

Sorry for this, the s3 backend only be added in https://github.com/dragonflyoss/image-service/blob/631db29759f4dceacaa7ff80b845a9d0107beef5/api/src/config.rs#L520, not in snapshshotter, maybe we don't need to handle it first.

statusCode = http.StatusNotFound
return
}
jsonResponse(w, credentialConfig)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe respond to the backendConfig directly here? In this way, when we add a new backend, we don't need to worry about handling miss here.

default:
return errors.Errorf("unknown backend type %s", backendType)
}

return nil
}

func serializeWithSecretFilter(obj interface{}) map[string]interface{} {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a UT for this func?

config/config.go Outdated
EnableStargz bool `toml:"enable_stargz"`
EnableReferrerDetect bool `toml:"enable_referrer_detect"`
TarfsConfig TarfsConfig `toml:"tarfs"`
EnableCredentialSource bool `toml:"enable_credential_source"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EnableBackendSource bool toml:"enable_backend_source"

@@ -124,11 +126,13 @@ type DeviceConfig struct {
// We don't have to persist configuration file for fscache since its configuration
// is passed through HTTP API.
func DumpConfigFile(c interface{}, path string) error {
if config.IsCredentialSourceEnabled() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsBackendSourceEnabled

@@ -25,6 +26,8 @@ import (
"github.com/containerd/nydus-snapshotter/pkg/prefetch"
)

const endpointGetCredential string = "/api/v1/daemons/%s/credential"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const endpointGetBackend string = "/api/v1/daemons/%s/backend"

sc.router.HandleFunc(endpointGetCredential, sc.getCredential()).Methods(http.MethodGet)
}

func (sc *Controller) getCredential() func(w http.ResponseWriter, r *http.Request) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getBackend

require.Equal(t, newCfg.Device.Backend.Config.Proxy, cfg.Device.Backend.Config.Proxy)
require.Equal(t, newCfg.Device.Backend.Config.BlobURLScheme, cfg.Device.Backend.Config.BlobURLScheme)
require.NotEqual(t, newCfg.Device.Backend.Config.Auth, cfg.Device.Backend.Config.Auth)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a blank line here.

Guijie Wang added 3 commits October 1, 2023 11:30
…ce of auth information

This change introduces a new startup option, enable_backend_source, which controls whether the authentication information is persisted or not. By default, enable_backend_source is set to false, which means that the authentication information will be persisted.

Signed-off-by: Guijie Wang <[email protected]>
… with secret tag

This commit introduces a new function, serializeWithSecretFilter, which filters fields with the 'secret' tag and prevents them from being persisted to local storage when the value is true.

Signed-off-by: Guijie Wang <[email protected]>
This commit introduces a new interface that allows nydusd to request backend configurations from the snapshotter via a Unix domain socket. Transferring all backend configs is to cope with the addition of different backend in the future.

Signed-off-by: Guijie Wang <[email protected]>
Guijie Wang added 5 commits October 31, 2023 16:15
Signed-off-by: Guijie Wang <[email protected]>
Signed-off-by: Guijie Wang <[email protected]>
Signed-off-by: Guijie Wang <[email protected]>
Signed-off-by: Guijie Wang <[email protected]>
Signed-off-by: Guijie Wang <[email protected]>
Copy link
Collaborator

@imeoer imeoer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@changweige changweige merged commit f894d55 into containerd:main Oct 31, 2023
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants